#ifndef MULITHREAD_SAVE_H
#define MULITHREAD_SAVE_H

#include "CompressThread.h"
#include <memory>
#include <string>
#include <cstdlib>
#include <fcntl.h>
#include <thread>
#include <unistd.h>
#include <sys/time.h>
#include <fmt/format.h>
#include <atomic>
#include <mutex>
#include <wx/event.h>
#include "PixelFormat.h"

wxDECLARE_EVENT(EVT_MULTIWRITE_ERR,wxCommandEvent);

class MuliThreadSave
{
    public:
        MuliThreadSave(wxEvtHandler* _evtHandler);
        virtual ~MuliThreadSave();
        std::string StartSaveImage(std::string path,int32_t width,int32_t height,pixelFormat format);
        void SaveImage(unsigned char* imageData,uint64_t timestamp=0);
        void StopSaveImage();
        void SetCmpAcceleration(int value);
    private:
        std::unique_ptr<CompressThread> cmpThreadPool;
        std::thread saveThread;
        void SaveImageFunc();  //完成文件真正的保存动作
        int fd=0;
        int32_t frameCount=0;
        int32_t imageSize;
        std::atomic<bool> ErrFlag=false;
        std::atomic<bool> threadExitFlag=false;
        wxEvtHandler* evtHandler;
        int cmpAcc=100;
};

#endif
